package com.example;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.Properties;

/**
 * 使用jdbc修改tb_brand表中的一条数据
 */

public class UpdateTest {
    public static void main(String[] args) throws Exception {
        System.out.println(System.getProperty("user.dir"));
        Properties prop=new Properties();
        prop.load(new FileInputStream("JDBC-Demo/src/druid.properties"));
        DataSource dataSource = DruidDataSourceFactory.createDataSource(prop);
        Connection conn = dataSource.getConnection();

        int id=4;
        String brand_name="香飘飘";
        String company_name="香飘飘";
        int ordered=1000;
        String description="香飘飘飞起来";
        int status =1;
        String sql="update tb_brand set brand_name=?,company_name=?,ordered=?,description=?,status=? where id=?";

        PreparedStatement pstmt = conn.prepareStatement(sql);

        pstmt.setString(1,brand_name);
        pstmt.setString(2,company_name);
        pstmt.setInt(3,ordered);
        pstmt.setString(4,description);
        pstmt.setInt(5,status);
        pstmt.setInt(6,id);

        int i = pstmt.executeUpdate();
        System.out.println(i>0);


    }
}
